//
//  TMLinkLabel.swift
//  TestPwp
//
//  Created by Denny on 2018/11/23.
//  Copyright © 2018 Denny. All rights reserved.
//

import Cocoa

class TMLinkLabel: NSTextField {
    
    ///The closure is option,you can custom click event
    public var clickClosure:((_ sender: Any?) ->Void)? = nil
    
    override init(frame frameRect: NSRect) {
        super.init(frame: frameRect);
        self.setupView();
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder);
        self.setupView();
    }
    
    /**
     
        The func setup click Gesture.
     
    */
    
    private func setupView(){
        
        let clickGes = NSClickGestureRecognizer.init(target: self, action: #selector(clickTextField(_ :)));
        self.addGestureRecognizer(clickGes);
        self.textColor = NSColor.init(red: 0x00/0xff, green: 0x7a/0xff, blue: 0xb9/0xff, alpha: 1.0);
    }
    
    /**
     
     The func is called when the *TMLinkLabel* is clicked.
     
     - Parameter sender: The target of *NSClickGestureRecognizer*
     
     */
    
    @objc private func clickTextField(_ sender: Any?) {
        
        print("clickTextField");
        
        self.clickClosure?(sender);
        
    }
    
}
